/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmRegistration.java
 *
 * Created on Apr 5, 2011, 4:32:35 PM
 */
package khmhappointmentsystem;

import java.sql.PreparedStatement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author mbelisle
 */
public class FrmRegistration extends javax.swing.JInternalFrame {

    /** Creates new form FrmRegistration */
    public FrmRegistration() {
        initComponents();
        setCalendarDate();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        lblftname = new javax.swing.JLabel();
        lblltname = new javax.swing.JLabel();
        txtftname = new javax.swing.JTextField();
        txtltname = new javax.swing.JTextField();
        lbladdress = new javax.swing.JLabel();
        lblssn = new javax.swing.JLabel();
        txtssn = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        lbltelephone = new javax.swing.JLabel();
        txttelephone = new javax.swing.JTextField();
        cmdcancel = new javax.swing.JButton();
        cmdsave = new javax.swing.JButton();
        lblsex = new javax.swing.JLabel();
        lblDOB = new javax.swing.JLabel();
        calDOB = new com.toedter.calendar.JDateChooser();
        lblphone = new javax.swing.JPanel();
        lblfirst = new javax.swing.JLabel();
        lbllast = new javax.swing.JLabel();
        txtFirstname = new javax.swing.JTextField();
        txtLastname = new javax.swing.JTextField();
        lblRelation = new javax.swing.JLabel();
        txtRelation = new javax.swing.JTextField();
        lblstreet = new javax.swing.JLabel();
        txtStreetAddress = new javax.swing.JTextField();
        lbldistrict = new javax.swing.JLabel();
        txtDistrict = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtphone = new javax.swing.JTextField();
        lblgender = new javax.swing.JLabel();
        txtgender = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtaddress = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        cmbDistrict = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(khmhappointmentsystem.Main.class).getContext().getResourceMap(FrmRegistration.class);
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        setBorder(null);
        setClosable(true);
        setIconifiable(true);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N

        lblftname.setText(resourceMap.getString("lblftname.text")); // NOI18N
        lblftname.setName("lblftname"); // NOI18N

        lblltname.setText(resourceMap.getString("lblltname.text")); // NOI18N
        lblltname.setName("lblltname"); // NOI18N

        txtftname.setText(resourceMap.getString("txtftname.text")); // NOI18N
        txtftname.setName("txtftname"); // NOI18N

        txtltname.setText(resourceMap.getString("txtltname.text")); // NOI18N
        txtltname.setName("txtltname"); // NOI18N

        lbladdress.setText(resourceMap.getString("lbladdress.text")); // NOI18N
        lbladdress.setName("lbladdress"); // NOI18N

        lblssn.setText(resourceMap.getString("lblssn.text")); // NOI18N
        lblssn.setName("lblssn"); // NOI18N

        txtssn.setText(resourceMap.getString("txtssn.text")); // NOI18N
        txtssn.setName("txtssn"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        lbltelephone.setText(resourceMap.getString("lbltelephone.text")); // NOI18N
        lbltelephone.setName("lbltelephone"); // NOI18N

        txttelephone.setText(resourceMap.getString("txttelephone.text")); // NOI18N
        txttelephone.setName("txttelephone"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(khmhappointmentsystem.Main.class).getContext().getActionMap(FrmRegistration.class, this);
        cmdcancel.setAction(actionMap.get("cancel")); // NOI18N
        cmdcancel.setIcon(resourceMap.getIcon("cmdcancel.icon")); // NOI18N
        cmdcancel.setText(resourceMap.getString("cmdcancel.text")); // NOI18N
        cmdcancel.setName("cmdcancel"); // NOI18N

        cmdsave.setAction(actionMap.get("save")); // NOI18N
        cmdsave.setIcon(resourceMap.getIcon("cmdsave.icon")); // NOI18N
        cmdsave.setText(resourceMap.getString("cmdsave.text")); // NOI18N
        cmdsave.setName("cmdsave"); // NOI18N

        lblsex.setText(resourceMap.getString("lblsex.text")); // NOI18N
        lblsex.setName("lblsex"); // NOI18N

        lblDOB.setText(resourceMap.getString("lblDOB.text")); // NOI18N
        lblDOB.setName("lblDOB"); // NOI18N

        calDOB.setName("calDOB"); // NOI18N

        lblphone.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        lblphone.setName("lblphone"); // NOI18N

        lblfirst.setText(resourceMap.getString("lblfirst.text")); // NOI18N
        lblfirst.setName("lblfirst"); // NOI18N

        lbllast.setText(resourceMap.getString("lbllast.text")); // NOI18N
        lbllast.setName("lbllast"); // NOI18N

        txtFirstname.setText(resourceMap.getString("txtFirstname.text")); // NOI18N
        txtFirstname.setName("txtFirstname"); // NOI18N

        txtLastname.setText(resourceMap.getString("txtLastname.text")); // NOI18N
        txtLastname.setName("txtLastname"); // NOI18N

        lblRelation.setText(resourceMap.getString("lblRelation.text")); // NOI18N
        lblRelation.setName("lblRelation"); // NOI18N

        txtRelation.setText(resourceMap.getString("txtRelation.text")); // NOI18N
        txtRelation.setName("txtRelation"); // NOI18N

        lblstreet.setText(resourceMap.getString("lblstreet.text")); // NOI18N
        lblstreet.setName("lblstreet"); // NOI18N

        txtStreetAddress.setText(resourceMap.getString("txtStreetAddress.text")); // NOI18N
        txtStreetAddress.setName("txtStreetAddress"); // NOI18N

        lbldistrict.setText(resourceMap.getString("lbldistrict.text")); // NOI18N
        lbldistrict.setName("lbldistrict"); // NOI18N

        txtDistrict.setText(resourceMap.getString("txtDistrict.text")); // NOI18N
        txtDistrict.setName("txtDistrict"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        txtphone.setText(resourceMap.getString("txtphone.text")); // NOI18N
        txtphone.setName("txtphone"); // NOI18N

        lblgender.setText(resourceMap.getString("lblgender.text")); // NOI18N
        lblgender.setName("lblgender"); // NOI18N

        txtgender.setText(resourceMap.getString("txtgender.text")); // NOI18N
        txtgender.setName("txtgender"); // NOI18N

        javax.swing.GroupLayout lblphoneLayout = new javax.swing.GroupLayout(lblphone);
        lblphone.setLayout(lblphoneLayout);
        lblphoneLayout.setHorizontalGroup(
            lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(lblphoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(lblphoneLayout.createSequentialGroup()
                        .addComponent(lblfirst)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFirstname, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
                    .addGroup(lblphoneLayout.createSequentialGroup()
                        .addComponent(lbllast)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtLastname, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
                    .addGroup(lblphoneLayout.createSequentialGroup()
                        .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblRelation)
                            .addComponent(lblgender))
                        .addGap(18, 18, 18)
                        .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtgender, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtRelation, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))))
                .addGap(18, 18, 18)
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblstreet)
                    .addComponent(lbldistrict)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtDistrict, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStreetAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtphone, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        lblphoneLayout.setVerticalGroup(
            lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(lblphoneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblfirst)
                    .addComponent(txtFirstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblstreet)
                    .addComponent(txtStreetAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbllast)
                    .addComponent(txtLastname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbldistrict)
                    .addComponent(txtDistrict, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblRelation)
                    .addComponent(txtRelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtphone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(lblphoneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblgender)
                    .addComponent(txtgender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(55, Short.MAX_VALUE))
        );

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        txtaddress.setText(resourceMap.getString("txtaddress.text")); // NOI18N
        txtaddress.setName("txtaddress"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        cmbDistrict.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Corozal", "Orange Walk", "Belize", "Cayo", "Stann Creek", "Toledo", " " }));
        cmbDistrict.setName("cmbDistrict"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(69, 69, 69)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblftname)
                            .addComponent(lblssn)
                            .addComponent(lbladdress)
                            .addComponent(lblDOB))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtaddress)
                            .addComponent(calDOB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtssn)
                            .addComponent(txtftname, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(cmbDistrict, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbltelephone)
                            .addComponent(lblltname)
                            .addComponent(lblsex))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txttelephone, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
                            .addComponent(txtltname))))
                .addContainerGap(54, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addComponent(cmdsave, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 139, Short.MAX_VALUE)
                .addComponent(cmdcancel, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(65, 65, 65))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblphone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(122, 122, 122)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(145, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(455, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblftname)
                    .addComponent(txtftname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblltname)
                    .addComponent(txtltname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(lblssn)
                    .addComponent(txtssn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbltelephone)
                    .addComponent(txttelephone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDOB)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(calDOB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lbladdress)
                            .addComponent(txtaddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblsex)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(cmbDistrict, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(74, 74, 74)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblphone, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdcancel)
                    .addComponent(cmdsave))
                .addGap(26, 26, 26))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-502)/2, (screenSize.height-642)/2, 502, 642);
    }// </editor-fold>//GEN-END:initComponents

    void setCalendarDate() {
        calDOB.setDate(new java.util.Date());
    }

    @Action
    public void cancel() {
        this.dispose();
    }

    @Action
    public void save() {
        //create object for date
        DateFormat MDY_Formatter = new SimpleDateFormat("yyyy-MM-dd");
        String pt_DOB = MDY_Formatter.format(calDOB.getDate());

        JComboBox District = new JComboBox();
        String pt_District = cmbDistrict.getSelectedItem().toString();

        String pt_ftname = txtftname.getText();//patient first name
        String pt_ltname = txtltname.getText();//patient last name
        String pt_ssn = txtssn.getText();//patient ssn number
        String pt_telephone = txttelephone.getText();//patient telephone number
        String pt_age = getage(calDOB.getDate());//patient age
        String pt_sex = jComboBox1.getSelectedItem().toString();//patient sex
        String pt_address = txtaddress.getText();//patient street address
        String kinftname = txtFirstname.getText();//next of kin first name
        String kinltname = txtLastname.getText();//next of kin lastname
        String kinsex = txtgender.getText();//next of kin sex
        String kinstreet = txtStreetAddress.getText();//next of kin street address
        String kindistrict = txtDistrict.getText();//next of kin district
        String kinrelation = txtRelation.getText();//next of kin relation
        String kinphone = txtphone.getText();//next of kin phone

        try {
            String query = "Insert into Patient_Info ("
                    + " pt_ssn,"
                    + "pt_ftname,"
                    + " pt_ltname,"
                    + "pt_address,"
                    + "pt_district,"
                    + "pt_DOB,"
                    + " pt_age, "
                    + "pt_sex, "
                    + " pt_telephone,"
                    + "kinftname,"
                    + "kinltname,"
                    + "kinsex,"
                    + "kinstreet,"
                    + "kindistrict,"
                    + "kinrelation,"
                    + "kinphone)"
                    + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            PreparedStatement pstmt = Environment.getDbConn().prepareStatement(query);

            pstmt.setString(1, pt_ssn);
            pstmt.setString(2, pt_ftname);
            pstmt.setString(3, pt_ltname);
            pstmt.setString(4, pt_address);
            pstmt.setString(5, pt_District);
            pstmt.setString(6, pt_DOB);
            pstmt.setString(7, pt_age);
            pstmt.setString(8, pt_sex);
            pstmt.setString(9, pt_telephone);
            pstmt.setString(10, kinftname);
            pstmt.setString(11, kinltname);
            pstmt.setString(12, kinsex);
            pstmt.setString(13, kinstreet);
            pstmt.setString(14, kindistrict);
            pstmt.setString(15, kinrelation);
            pstmt.setString(16, kinphone);

            pstmt.executeUpdate();
            JOptionPane.showMessageDialog(rootPane, "Patient Registration Completed.");

            //Clear textboxes
            txtftname.setText("");
            txtltname.setText("");
            txtssn.setText("");
            txttelephone.setText("");
            txtaddress.setText("");
            txtFirstname.setText("");
            txtLastname.setText("");
            txtgender.setText("");
            txtStreetAddress.setText("");
            txtDistrict.setText("");
            txtRelation.setText("");
            txtphone.setText("");
        } catch (Exception e) {
            System.out.println("Error occured while registering patient.");
            e.printStackTrace();
        }
    }

    private String getage(Date dateOfBirth) {
        Calendar dob = Calendar.getInstance();
        dob.setTime(dateOfBirth);
        Calendar today = Calendar.getInstance();
        int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
        if (today.get(Calendar.DAY_OF_YEAR) <= dob.get(Calendar.DAY_OF_YEAR)) {
            age--;
        }
        return String.valueOf(age);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser calDOB;
    private javax.swing.JComboBox cmbDistrict;
    private javax.swing.JButton cmdcancel;
    private javax.swing.JButton cmdsave;
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel lblDOB;
    private javax.swing.JLabel lblRelation;
    private javax.swing.JLabel lbladdress;
    private javax.swing.JLabel lbldistrict;
    private javax.swing.JLabel lblfirst;
    private javax.swing.JLabel lblftname;
    private javax.swing.JLabel lblgender;
    private javax.swing.JLabel lbllast;
    private javax.swing.JLabel lblltname;
    private javax.swing.JPanel lblphone;
    private javax.swing.JLabel lblsex;
    private javax.swing.JLabel lblssn;
    private javax.swing.JLabel lblstreet;
    private javax.swing.JLabel lbltelephone;
    private javax.swing.JTextField txtDistrict;
    private javax.swing.JTextField txtFirstname;
    private javax.swing.JTextField txtLastname;
    private javax.swing.JTextField txtRelation;
    private javax.swing.JTextField txtStreetAddress;
    private javax.swing.JTextField txtaddress;
    private javax.swing.JTextField txtftname;
    private javax.swing.JTextField txtgender;
    private javax.swing.JTextField txtltname;
    private javax.swing.JTextField txtphone;
    private javax.swing.JTextField txtssn;
    private javax.swing.JTextField txttelephone;
    // End of variables declaration//GEN-END:variables
}
